package com.gt.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gt.common.core.controller.BaseController;
import com.gt.common.core.domain.AjaxResult;
import com.gt.admin.domain.QualityItem;
import com.gt.admin.service.IQualityItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 质控指标controller
 */
@Api(tags = "sc-质控指标")
@RestController
@RequestMapping("/quality-config/item")
public class QualityItemController extends BaseController {

    @Autowired
    private IQualityItemService qualityItemService;

    /**
     * 根据上级目录id查询质控指标列表
     */
    @ApiOperation("根据上级目录id查询质控指标列表")
    @GetMapping("/{superId}")
    public AjaxResult listByQua(@PathVariable("superId") Long superId){
        LambdaQueryWrapper<QualityItem> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(QualityItem::getSuperId, superId);
        return AjaxResult.success(qualityItemService.list(queryWrapper));
    }

    /**
     * 查询质控指标列表
     */
    @ApiOperation("查询质控指标")
    @GetMapping("/list")
    public AjaxResult list(QualityItem qualityItem){
        LambdaQueryWrapper<QualityItem> queryWrapper = new LambdaQueryWrapper<>(qualityItem);
        return AjaxResult.success(qualityItemService.list(queryWrapper));
    }

    /**
     * 修改质控指标
     */
    @ApiOperation("修改质控指标")
    @PutMapping
    public AjaxResult update(@RequestBody QualityItem qualityItem){
        return toAjax(qualityItemService.updateById(qualityItem));
    }

    /**
     * 新增质控指标
     */
    @ApiOperation("新增质控指标")
    @PostMapping
    public AjaxResult insert(@RequestBody QualityItem qualityItem){
        return toAjax(qualityItemService.save(qualityItem));
    }

    /**
     * 删除质控指标
     */
    @ApiOperation("删除质控指标")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        return toAjax(qualityItemService.removeById(id));
    }
}
